import {
    defineConfig,
    loadEnv,
} from "vite"
import vue from "@vitejs/plugin-vue"
import {resolve} from "path"
import electron from "vite-plugin-electron";
import setupExtend from "vite-plugin-vue-setup-extend"

export default defineConfig(({mode}) => {
    const env = loadEnv(mode, process.cwd())
    return {
        base: "./",
        plugins: [
            vue(),
            setupExtend(),
            electron({
                main: {
                    entry: "electron/main.js",
                },
            }),
        ],
        resolve: {
            alias: [
                {
                    find: "@",
                    replacement: resolve(__dirname, "src"),
                },
                {
                    find: "@assets",
                    replacement: resolve(__dirname, "src/assets"),
                },
                {
                    find: "@c",
                    replacement: resolve(__dirname, "src/components"),
                },
            ],
        },
        css: {
            preprocessorOptions: {
                less: {
                    additionalData: `
                        @import "@/assets/less/variables.less";
                    `,
                    javascriptEnabled: true,
                },
            },
        },
        server: {
            host: "0.0.0.0",
            port: 5173,
            open: true,
            strictPort: true,
            proxy: {
                "/api": {
                    target: env.VITE_API_URL,
                    changeOrigin: true,
                },
            },
        },
        build: {
            assetsDir: "static",
        },
    }
})